home *** CD-ROM | disk | FTP | other *** search
/ Power Programmierung / Power-Programmierung (Tewi)(1994).iso / magazine / nan_news / toolkit / dayofyr.prg < prev    next >
Text File  |  1991-08-15  |  4KB  |  120 lines

  1. /*
  2.  * File......: DAYOFYR.PRG
  3.  * Author....: Jo W. French dba Practical Computing
  4.  * CIS_ID....: 74731,1751
  5.  * Date......: $Date:   15 Aug 1991 23:03:08  $
  6.  * Revision..: $Revision:   1.2  $
  7.  * Log file..: $Logfile:   E:/nanfor/src/dayofyr.prv  $
  8.  * 
  9.  * The functions contained herein are the original work of Jo W. French
  10.  * and are placed in the public domain.
  11.  *
  12.  * Modification history:
  13.  * ---------------------
  14.  *
  15.  * $Log:   E:/nanfor/src/dayofyr.prv  $
  16.  * 
  17.  *    Rev 1.2   15 Aug 1991 23:03:08   GLENN
  18.  * Forest Belt proofread/edited/cleaned up doc
  19.  * 
  20.  *    Rev 1.1   10 May 1991 23:59:38   GLENN
  21.  * Minor adjustment to header.
  22.  * 
  23.  *    Rev 1.0   01 Apr 1991 01:01:02   GLENN
  24.  * Nanforum Toolkit
  25.  *
  26.  */
  27.  
  28. /*  $DOC$
  29.  *  $FUNCNAME$
  30.  *     FT_DAYOFYR()
  31.  *  $CATEGORY$
  32.  *     Date/Time
  33.  *  $ONELINER$
  34.  *     Return calendar, fiscal or accounting day data
  35.  *  $SYNTAX$
  36.  *     FT_DAYOFYR( [ <dGivenDate> ], [ <nDayNum> ], [ <lIsAcct> ] ) 
  37.  *            -> aDateInfo
  38.  *  $ARGUMENTS$
  39.  *     <dGivenDate> is any valid date in any valid format.  Defaults
  40.  *     to current system date if not supplied.
  41.  *
  42.  *     <nDayNum> is a number from 1 to 371, signifying a day of a year.
  43.  *     Defaults to current day if not supplied.
  44.  *
  45.  *     <lIsAcct> is a logical which specifies the type of year to base
  46.  *     the return value on:  .F. = calendar or fiscal year,
  47.  *     .T. = accounting year.
  48.  *  $RETURNS$
  49.  *     A three element array containing the following data:
  50.  *
  51.  *        If <nDayNum> is specified:
  52.  *
  53.  *        aDateInfo[1] - The date of the specified day number
  54.  *        aDateInfo[2] - The beginning date of the year
  55.  *        aDateInfo[3] - The ending date of the year
  56.  *
  57.  *        If <nDayNum> is not specified:
  58.  *
  59.  *        aDateInfo[1] - The year and day as a character string "YYYYDDD"
  60.  *        aDateInfo[2] - The beginning date of the year
  61.  *        aDateInfo[3] - The ending date of the year
  62.  *  $DESCRIPTION$
  63.  *     FT_DAYOFYR() returns an array containing data about a day in the
  64.  *     calendar or fiscal year containing the given date.
  65.  *
  66.  *     The beginning of year date defaults to January 1st but may be
  67.  *     changed with FT_DATECNFG().
  68.  *  $EXAMPLES$
  69.  *     aDateInfo := FT_DAYOFYR( CTOD("03/31/91") )
  70.  *     ? aDateInfo[1]        // 1991090    (90th day of year 1991)
  71.  *     ? aDateInfo[2]        // 01/01/91
  72.  *     ? aDateInfo[3]        // 12/31/91
  73.  *
  74.  *     aDateInfo := FT_DAYOFYR( , 90 )    // assume current date is 3/31/91
  75.  *     ? aDateInfo[1]        // 03/31/91    (90th day of year)
  76.  *     ? aDateInfo[2]        // 01/01/91
  77.  *     ? aDateInfo[3]        // 12/31/91
  78.  *
  79.  *     aDateInfo := FT_DAYOFYR( , 90, .T. )
  80.  *     ? aDateInfo[1]        // 03/29/91    (90th day of accounting year)
  81.  *     ? aDateInfo[2]        // 12/30/90    (1st day of accounting year)
  82.  *     ? aDateInfo[3]        // 12/28/91    (last day of accounting year)
  83.  *  $SEEALSO$
  84.  *     FT_DATECNFG()
  85.  *  $END$
  86. */
  87.  
  88. FUNCTION FT_DAYOFYR(dGivenDate,nDayNum,lIsAcct)
  89.   LOCAL lIsDay, nTemp, aRetVal
  90.  
  91.   IF dGivenDate == NIL .OR. !VALTYPE(dGivenDate) $ 'NDL'
  92.      dGivenDate := DATE()
  93.   ELSEIF VALTYPE(dGivenDate) == 'N'
  94.      nDayNum    := dGivenDate
  95.      dGivenDate := DATE()
  96.   ELSEIF VALTYPE(dGivenDate) == 'L'
  97.      lIsAcct    := dGivenDate
  98.      dGivenDate := DATE()
  99.   ENDIF
  100.  
  101.   lIsDay  := IF(nDayNum == NIL .OR. VALTYPE(nDayNum) != 'N', .F., .T.)
  102.   lIsAcct := IF(lIsAcct == NIL .OR. VALTYPE(lIsAcct) != 'L', .F., lIsAcct)
  103.  
  104.   IF lIsAcct
  105.      aRetVal := FT_ACCTYEAR(dGivenDate)
  106.   ELSE
  107.      aRetVal := FT_YEAR(dGivenDate)
  108.   ENDIF
  109.  
  110.   IF lIsDay
  111.      nTemp := aRetVal[3] - aRetVal[2] + 1
  112.      nDayNum := IF(nDayNum > 0 .AND. nDayNum <= nTemp , nDayNum, nTemp)
  113.      aRetVal[1] := aRetVal[2] + nDayNum - 1
  114.   ELSE
  115.      aRetVal[1] += PADL(LTRIM(STR( dGivenDate - aRetVal[2] + 1, 3)), 3, '0')
  116.   ENDIF
  117.  
  118. RETURN aRetVal
  119.  
  120.